JavaScript

A5.u.arrayresolver Method

Syntax

A5.u.array.resolver(array[,joiner])

Arguments

arrayarray

The array to create the resolver from.

joinerstringfunctionboolean

How the values in the resolved array should be joined.

Returns

resolverfunction

The resolver function that will return the result of the passed in array.

Description

Create a resolver function from the passed in array.

Discussion

The A5.u.array.resolver method will take an array and return a function that can be called one or more times at a later point. The array can contain values and functions. These functions will be called when the array is being resolved. The arguments and scope of the resolver will be passed to the "child" functions. If the "child" function returns and array then the array will be automatically concatenated onto the result. Otherwise the returned value will be inserted in place of the "child" function.

The "joiner" argument can be used to automatically combine the resolved array into a string or custom result. If the passed in "joiner" argument is a string then the resulting array will be joined with that string. If the "joiner" is a function then the "joiner" function will be called with the resulting array. If no "joiner" or a value of false is passed in then the array will be returned directly.

Example

var args = [function(a){ return a.toCase('proper')+'/'+this.b},'hello!'];
var obj = {b: 'bar'};
obj.getString = A5.u.array.resolver(args,' ');
var str = obj.getString('foo');
// str = "Foo/bar hello!"
obj.b = '3'
str = obj.getString('1');
// str = "1/3 hello!"